﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 开单.Dao.基础;
using 开单.Model.基础;

namespace ClientApplication.ComControl
{
    public partial class UCHp : UserControl
    {
        HpxxDao hpxxDao = new HpxxDao();
        HpxxEntity hpxxEntity = new HpxxEntity();
        DataTable dt = new DataTable();
        public delegate void UcHpEventHandler(HpxxEntity hpxxEntity);
        public event UcHpEventHandler UcHpEvent;

        public UCHp()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                dt = hpxxDao.GetHpxxDtByHp_jp(textBox1.Text);
                if (dt.Rows.Count == 0) { MessageBox.Show("没有查到"); return; }
                dataGridView1.DataSource = dt;
                dataGridView1.Focus();
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.RowCount == 0 || e.RowIndex == -1) { return; }
            hpxxEntity = hpxxDao.GetHpxxEntityByHpName(dataGridView1[1, e.RowIndex].Value.ToString());

            if (UcHpEvent != null)
                UcHpEvent(hpxxEntity);
            this.Visible = false;
        }

        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (dataGridView1.RowCount == 0 || dataGridView1.CurrentCell.RowIndex == -1) { return; }
                hpxxEntity = hpxxDao.GetHpxxEntityByHpName(dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString());
                if (UcHpEvent != null)
                    UcHpEvent(hpxxEntity);
                this.Visible = false;
            }
        }
    }
}
